<?php
    
    @include_once("conn.php");
    @include_once("common.php");
    

    $phone = $_POST["phone"];
    if(!$phone){
        argErr();
    }


    // 执行查询语句
    $search  = "SELECT s.id,s.gid,s.buyNum,g.goodsName,g.goodsPrice,g.bigPicList FROM `shopping` as s,`goodslist` as g where s.gid = g.goodsId and s.phone ='$phone'; ";
 
    $result = mysqli_query($conn,$search);

    //循环解析数据  先解析 在将结果赋值给$item
    // 解析成功 => 解析的数据 => 继续解析
    // 解析失败 => false    =>跳出循环
        
    $all = array(); 
    while( $item = mysqli_fetch_assoc($result)){
        $item["bigPicList"] = explode(",",$item["bigPicList"]);
        $item["goodsImg"] =  $item["bigPicList"][0];
       array_push($all,$item); 
    }


    // 数据处理  
    $msg = array();
    if(count($all)>0){ 
        // echo json_encode($item);
        $msg["status"] = true; 
        $msg["detail"] = "ok"; 
        $msg["data"] = $all; 
    }else{
        $msg["status"] = false; 
        $msg["detail"] = "not found"; 
        $msg["list"] = array(); 
    }

    echo json_encode($msg);


    /* {
        status:true,
        detail:"查询成功",
        data
    } */


    // 单数据  => 直接解析
    // 多数据  => 循环解析 => 放到数组中

?>